﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Radiation___IM
{
    public class ChannelManager
    {
        private static ChannelManager m_manager;

        public static void Init()
        {
            m_manager = new ChannelManager();
        }

        public static ChannelManager Instance
        {
            get
            {
                return m_manager;
            }
        }

        // dynamic part 
        private Hashtable m_channel;

        public Channel this[string name]
        {
            get
            {
                if (m_channel.ContainsKey(name))
                    return (Channel)m_channel[name];
                return null;
            }
        }

        public Hashtable Channels
        {
            get
            {
                return m_channel;
            }
        }

        public ChannelManager()
        {
            m_channel = new Hashtable();

            // create the default channel
            Channel def = new Channel("default");
            m_channel.Add(def.Name, def);
            def.superSetProtectable(false);
        }

        public rvalue add(string name)
        {
            if (!m_channel.ContainsKey(name))
            {
                m_channel.Add(name, new Channel(name));
                return rvalue.CHANNEL_ADDED;
            }
            else
                return rvalue.CHANNEL_ALREADY_EXISTS;
        }

        public rvalue delete(string name)
        {
            if (m_channel.ContainsKey(name))
            {
                m_channel.Remove(name);
                return rvalue.CHANNEL_DELETED;
            }
            else
                return rvalue.CHANNEL_NOT_FOUND;
        }
    }
}
